package data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.EntityName;
import com.google.appengine.api.datastore.Entity;

public class Guest extends AbstractData {
	private long id = -1;
	
	private Salutation salutation;
	private String salutationString;
	private String firstName;
	private String lastName;
	private String gender;
	private Date birthday;
	private String mail;
	private String nationalityString;
	private String idNumber;
	private String passportNumber;
	private String driverlicense;
	private String socialSecuritycard;
	private String addressLine1;
	private String addressLine2;
	private String country;
	private String state;
	private String city;
	private String pincode;
	private String phone;
	private String fax;
	private String company;
	private String designation;
	private String officeAddress;
	private String officeCountry;
	private String officeState;
	private String officeCity;
	private String officePincode;
	private String officePhone1;
	private String officePhone2;
	private String officeFax;
	private String preference;
	private String officeEmail;
	private boolean isVIP;
	private boolean isBlackList;
	private String note;
	private List<CreditCard> creditCard;
	private String creditCardString;
	
	
	public Guest()
	{}
	
	public Guest(long id)
	{
		this.id = id;
	}

	
	public long getId() {
		return id;
	}
	
	public void setId(long id)
	{
		this.id = id;
	}


	public Salutation getSalutation() {
			if (salutation == null && !(salutationString == null || salutationString.isEmpty())) {
				if(salutationString.equals("0"))
				{
					salutation = null;
				}else{
			Salutation s = new Salutation(Long.parseLong(salutationString));
			s.LoadData();		
			salutation = s;
		}
			}
		
		return salutation;
	}

	public void setSalutation(Salutation salutation) {
		this.salutationString = String.format("%d", salutation.getId());
		this.salutation = salutation;
	}

	public String getSalutationString() {
		return salutationString;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}
	public String getIdNumber() {
		return idNumber;
	}

	public void setIdNumber(String idNumber) {
		this.idNumber = idNumber;
	}

	public String getAddressLine1() {
		return addressLine1;
	}

	public void setAddressLine1(String addressLine1) {
		this.addressLine1 = addressLine1;
	}

	public String getAddressLine2() {
		return addressLine2;
	}

	public void setAddressLine2(String addressLine2) {
		this.addressLine2 = addressLine2;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getPincode() {
		return pincode;
	}

	public void setPincode(String pincode) {
		this.pincode = pincode;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getDesignation() {
		return designation;
	}

	public void setDesignation(String designation) {
		this.designation = designation;
	}

	public String getOfficeAddress() {
		return officeAddress;
	}

	public void setOfficeAddress(String officeAddress) {
		this.officeAddress = officeAddress;
	}

	public String getOfficeCountry() {
		return officeCountry;
	}

	public void setOfficeCountry(String officeCountry) {
		this.officeCountry = officeCountry;
	}

	public String getOfficeState() {
		return officeState;
	}

	public void setOfficeState(String officeState) {
		this.officeState = officeState;
	}

	public String getOfficeCity() {
		return officeCity;
	}

	public void setOfficeCity(String officeCity) {
		this.officeCity = officeCity;
	}

	public String getOfficePincode() {
		return officePincode;
	}

	public void setOfficePincode(String officePincode) {
		this.officePincode = officePincode;
	}

	public String getOfficePhone1() {
		return officePhone1;
	}

	public void setOfficePhone1(String officePhone1) {
		this.officePhone1 = officePhone1;
	}

	public String getOfficePhone2() {
		return officePhone2;
	}

	public void setOfficePhone2(String officePhone2) {
		this.officePhone2 = officePhone2;
	}

	public String getOfficeFax() {
		return officeFax;
	}

	public void setOfficeFax(String officeFax) {
		this.officeFax = officeFax;
	}

	public String getPreference() {
		return preference;
	}

	public void setPreference(String preference) {
		this.preference = preference;
	}

	public boolean isVIP() {
		return isVIP;
	}

	public void setVIP(boolean isVIP) {
		this.isVIP = isVIP;
	}

	public boolean isBlackList() {
		return isBlackList;
	}

	public void setBlackList(boolean isBlackList) {
		this.isBlackList = isBlackList;
	}

	public void setSalutationString(String salutationString) {
		this.salutationString = salutationString;
	}

	public void setNationalityString(String nationalityString) {
		this.nationalityString = nationalityString;
	}
	
	public String getNationalityString() {
		return nationalityString;
	}

	public String getPassportNumber() {
		return passportNumber;
	}

	public void setPassportNumber(String passportNumber) {
		this.passportNumber = passportNumber;
	}

	public String getDriverlicense() {
		return driverlicense;
	}

	public void setDriverlicense(String driverlicense) {
		this.driverlicense = driverlicense;
	}

	public String getSocialSecuritycard() {
		return socialSecuritycard;
	}

	public void setSocialSecuritycard(String socialSecuritycard) {
		this.socialSecuritycard = socialSecuritycard;
	}
	public String getOfficeEmail() {
		return officeEmail;
	}

	public void setOfficeEmail(String officeEmail) {
		this.officeEmail = officeEmail;
	}
	
	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}
	
	public List<CreditCard> getCreditCard() {
		if ((creditCard == null||creditCard.size()== 0) && !(creditCardString == null || creditCardString.isEmpty())) {
			String[] idOfList = SplitList(creditCardString);
			List<CreditCard> list = new ArrayList<CreditCard>();
			if(idOfList.length == 1 && idOfList[0].equals("")){
				creditCard = null;
			}else{
				for (String id : idOfList) {
					CreditCard a = new CreditCard(Long.parseLong(id));
					list.add(a);
				}
				for(CreditCard a : list)
					a.LoadData();
				
				creditCard = list;			
			}
		}
		return creditCard;
	}

	public void setCreditCard(List<CreditCard> creditCard) {
		this.creditCardString = CombineList(creditCard);
		this.creditCard = creditCard;
	}

	public String getCreditCardString() {
		return creditCardString;
	}

	public void setCreditCardString(String creditCardString) {
		this.creditCardString = creditCardString;
	}

	@Override
	public Entity getEntity() {
		Entity item;
		if(this.key == null)
			item = new Entity(EntityName.Guest);
		else
			item = new Entity(this.key);

	
		item.setProperty("salutation", this.salutationString);
		item.setProperty("firstName", this.firstName);
		item.setProperty("lastName", this.lastName);
		item.setProperty("state", this.state);
		item.setProperty("city", this.city);
		item.setProperty("phone", this.phone);
		item.setProperty("gender", this.gender);
		item.setProperty("birthday", this.birthday);
		item.setProperty("designation", this.designation);
		item.setProperty("mail", this.mail);
		item.setProperty("nationality", this.nationalityString);
		item.setProperty("idNumber", this.idNumber);
		item.setProperty("passportNumber", this.passportNumber);
		item.setProperty("driverlicense", this.driverlicense);
		item.setProperty("socialSecuritycard", this.socialSecuritycard);
		item.setProperty("addressLine1", this.addressLine1);
		item.setProperty("addressLine2", this.addressLine2);
		item.setProperty("country", this.country);
		item.setProperty("pincode", this.pincode);
		item.setProperty("fax", this.fax);
		item.setProperty("company", this.company);
		item.setProperty("officeAddress", this.officeAddress);
		item.setProperty("officeCountry", this.officeCountry);
		item.setProperty("officeState", this.officeState);
		item.setProperty("officeCity", this.officeCity);
		item.setProperty("officePincode", this.officePincode);
		item.setProperty("officePhone1", this.officePhone1);
		item.setProperty("officePhone2", this.officePhone2);
		item.setProperty("officeFax", this.officeFax);
		item.setProperty("officeEmail", this.officeEmail);
		item.setProperty("preference", this.preference);
		item.setProperty("isVIP", this.isVIP);
		item.setProperty("isBlackList", this.isBlackList);
		item.setProperty("note",this.note);
		item.setProperty("creditCardId",this.creditCardString);
		return item;
	}

	@Override
	public void setEntity(Entity entity) {
		
		this.id = entity.getKey().getId();
		this.salutationString = (String) entity.getProperty("salutation");
		this.firstName = (String) entity.getProperty("firstName");
		this.lastName= (String) entity.getProperty("lastName");
		this.gender= (String) entity.getProperty("gender");
		this.birthday= (Date) entity.getProperty("birthday");
		this.mail= (String) entity.getProperty("mail");
		this.nationalityString= (String) entity.getProperty("nationality");
		this.idNumber= (String) entity.getProperty("idNumber");
		this.passportNumber= (String) entity.getProperty("passportNumber");
		this.driverlicense= (String) entity.getProperty("driverlicense");
		this.socialSecuritycard= (String) entity.getProperty("socialSecuritycard");
		this.addressLine1= (String) entity.getProperty("addressLine1");
		this.addressLine2= (String) entity.getProperty("addressLine2");
		this.country= (String) entity.getProperty("country");
		this.state= (String) entity.getProperty("state");
		this.city= (String) entity.getProperty("city");
		this.pincode= (String) entity.getProperty("pincode");
		this.phone= (String) entity.getProperty("phone");
		this.fax= (String) entity.getProperty("fax");
		this.company= (String) entity.getProperty("company");
		this.designation= (String) entity.getProperty("designation");
		this.officeAddress= (String) entity.getProperty("officeAddress");
		this.officeCountry= (String) entity.getProperty("officeCountry");
		this.officeState= (String) entity.getProperty("officeState");
		this.officeCity= (String) entity.getProperty("officeCity");
		this.officePincode= (String) entity.getProperty("officePincode");
		this.officePhone1= (String) entity.getProperty("officePhone1");
		this.officePhone2= (String) entity.getProperty("officePhone2");
		this.officeFax= (String) entity.getProperty("officeFax");
		this.officeEmail= (String) entity.getProperty("officeEmail");
		this.preference= (String) entity.getProperty("preference");
		this.isVIP= (Boolean) entity.getProperty("isVIP");
		this.isBlackList= (Boolean) entity.getProperty("isBlackList");
		this.note = (String) entity.getProperty("note");
		this.creditCardString = (String) entity.getProperty("creditCardId");
		this.key = entity.getKey();
		
	}
	
	public void LoadData() {
		if (this.id > -1) {
			Entity entity = LoadData(EntityName.Guest, this.id);
			setEntity(entity);
		}
	}
}
